<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title></title>

	<link rel="stylesheet" href="./Public/Admin/Bootstrap/Css/bootstrap.min.css" />
	<link rel="stylesheet" href="./Public/Admin/Css/common.css" />
	<link rel="stylesheet" href="./Public/Admin/Uploadify/uploadify.css" />
	<script type="text/javascript" src='./Public/Admin/Js/jquery-1.7.2.min.js'></script>
	<script type="text/javascript" src='./Public/Admin/Uploadify/jquery.uploadify.js'></script>
	<script type="text/javascript" src='./Public/Admin/Ueditor/ueditor.config.js'></script>
	<script type="text/javascript" src='./Public/Admin/Ueditor/ueditor.all.min.js'></script>
	<script type="text/javascript" src='./Public/Admin/Js/goods.js'></script>
	
	<style type="text/css">
		/*去掉uploadify上传按钮的边框*/
	    .uploadify-button {
	        background-color: transparent;
	        border: none;
	        padding: 0;
	    }
	    .uploadify:hover .uploadify-button {
	        background-color: transparent;
    	}
    	.hide{
    		display: none;
    	}
    	body{
    		margin-bottom: 100px;
    	}
	</style> 
	<script type="text/javascript">
		var root = '__ROOT__';
		//图片上传提交地址
		var handler = '{:U("uploadEditor")}';
		var uploadify_path = './Public/Admin/Uploadify';
		var sess_name = "<?php echo session_name(); ?>";
		var sess_id = "<?php echo session_id(); ?>";
		//列表图上传地址
		var pic_uploader = '{:U("uploadPic")}';
		//商品图册上传地址
		var photo_uploader = '{:U("uploadPhoto")}';
		var upload_path = '__UPLOAD__';
		var delPic = '{:U("delPic")}';
		var getAttr = '{:U("getAttr")}';
	</script>
</head>
<body>
	<div class="container-fluid">
	<div class="row-fluid">
	<div class="span12">
	<!--//异步请求-->
	<script type="text/javascript">
		$(function(){
			
			$('select[name=category_cid]').change(function(){	
				//通过选择分类获得tid,然后发异步到数据，
				//查询tid所对应的类型属性，js组合字符串，插入到页面
				var type_typid = $('option:selected').attr('type_typid');

				$.ajax({
					type:"post",
					url:"<?php echo U('getTypeAttr')?>",
					data:{id:type_typid},
					dataType:'json',
					success:function(phpData){
						//规格(可选)
						var spec = '';
						//属性（不可选）
						var attr = '';
						$.each(phpData, function(k,v) {
							//如果是规格
							if(v.tclass == 1){
								spec += '<tr class="info">' +
								'<td>'+v.tname+'</td>' +
								'<td>' +
									'<select name="spec['+v.tid+'][value][]" id=""><option value="">请选择</option>';
										$.each(v.tvalue, function(kk,vv) {    
											 spec += '<option value="'+vv+'">'+vv+'</option>';                                                      
										});
									spec += '</select></td><td>附加价格：<input type="text" name="spec['+v.tid+'][price][]" id="" /></td>' +
										'<td><span class="btn btn-success add-spec">增加规格</span></td></tr>';
							
							}else{//属性
								attr += '<tr class="info">' + 
											'<td>'+v.tname+'</td>' + 
											'<td>' + 
											'<select name="attr['+v.tid+']" id=""><option value="">请选择</option>';
												
												$.each(v.tvalue, function(kk,vv) {    
													 attr += '<option value="'+vv+'">'+vv+'</option>';                                                      
												});
												
								attr += '</select></td></tr>';
							}                               
							
							
						});
						//在循环的外边给table添加tr和td
						$('#attr').html(attr);
						$('#spec').html(spec);
					}
				});
			})
		})
	</script>
	<form action="" method='post'>
		<fieldset>
			<legend>修改商品</legend>
			<table class='table table-bordered table-hover'>
				<thead>
					<tr>
						<th colspan="2" class="btn btn-primary">基本信息</th>
					</tr>
				</thead>
				<tbody>
					<tr class="info">
						<td>所属分类</td>
						<td>
							<select name="category_cid">
								<option value="0">-请选择-</option>
								<?php foreach ($cateData as $v){?>
									<!--<option value="<?php echo $v['cid']?>" type_typid="$v['type_typid']" selected ><?php echo $oldData['gvalues']?><?php echo $v['_html']?><?php echo $v['_name']?></option>-->
									<option value="<?php echo $v['cid']?>" type_typid="<?php echo $v['type_typid']?>" <?php if($v['cid']==$oldData['category_cid']){?>
                selected
               <?php }?>><?php echo $v['_name']?></option>
								<?php }?>
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>所属品牌</td>
						<td>
							<select name="brand_bid">
								<option value="0">-请选择-</option>
								<?php foreach ($brandData as $v){?>
									<option value="<?php echo $v['bid']?>" brand_bid="$v['brand_bid']" <?php if($oldData['brand_bid']==$v['bid']){?>
                selected
               <?php }?>><?php echo $v['bname']?></option>
								<?php }?>
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>商品名称</td>
						<td>
							<input type="text" name='gname' value="<?php echo $oldData['gname']?>" />
						</td>
					</tr>
					<tr class="info">
						<td>库存</td>
						<td>
							<input type="text" name='totalstore' value="<?php echo $oldData['totalstore']?>" />
						</td>
					</tr>
					<tr class="info">
						<td>货号</td>
						<td>
							<input type="text" name='gnum' value="<?php echo $oldData['gnum']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>单位</td>
						<td>
							<input type="text" name='gunit' value="<?php echo $oldData['gunit']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>市价场</td>
						<td>
							<input type="text" name='mkprice' value="<?php echo $oldData['mkprice']?>" />
						</td>
					</tr>
					<tr class="info">
						<td>商城价</td>
						<td>
							<input type="text" name='shopprice' value="<?php echo $oldData['shopprice']?>" />
						</td>
					</tr>
					<tr class="info">
						<td>点击次数</td>
						<td>
							<input type="text" name='clickrate' value="<?php echo $oldData['clickrate']?>" />
						</td>
					</tr>
				</tbody>
			</table>

			<p class="btn btn-primary">商品属性</p>
			<table class="table table-bordered table-hover" id='attr' class="info">
				
					<?php foreach ($attr2 as $v){?>
					<?php if($v['tclass']==0 ){?>
                
					<tr class="info">
						<td><?php echo $v['tname']?></td>
						<td>
							<select name="attr[<?php echo $v['tid']?>]">
								<option value="0">请选择</option>
								<?php foreach ($v['tvalue'] as $vv){?>
								<option value="<?php echo $vv?>" <?php if($v['gvalues']==$vv){?>
                selected
               <?php }?> ><?php echo $vv?></option>
								<?php }?>
							</select>
						</td>
					</tr>
					
               <?php }?>
					<?php }?>
				
			</table>
			<p class="btn btn-primary">商品规格</p>
			<table class="table table-bordered table-hover" id='spec'>
				
					<?php foreach ($attr2 as $v){?>
					<?php if($v['tclass']==1 ){?>
                
					<tr class="info">
						<td><?php echo $v['tname']?></td>
						<td>
							<select name="spec[<?php echo $v['tid']?>][value][]">
								<option value="0">请选择</option>
								<?php foreach ($v['tvalue'] as $vv){?>
								<option value="<?php echo $vv?>" <?php if($v['gvalues']==$vv){?>
                selected
               <?php }?>><?php echo $vv?></option>
								<?php }?>
							</select>
							<td>附加价格：<input type="text" name="spec[<?php echo $v['tid']?>][price][]" id="" value="<?php echo $v['addprice']?>"/></td>
						</td>
						
					</tr>
					
               <?php }?>
					<?php }?>
				
			</table>

			<table class='table table-bordered'>
				<tr>
					<th colspan="3" class="btn btn-primary">列表图</th>
				</tr>
				<tr class="info">
					<td>上传图片</td>
					<td>
						<!--<input type="file" name='listview' id='pic'/>-->
						<!--列表图单图上传-->
							<div lab="uploadFile">
						    <input id="fil" type="file"  multiple="true">
						    	<!--<input type="text" name="listview" id="listview" />-->
						    <span>类型: *.jpg,*.png 大小: 2000KB 数量: 1</span>
						    <script type="text/javascript">
						        $(function() {
						            $('#fil').uploadify({
						                'formData'     : {//POST数据
						                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
						                },
						                'fileTypeDesc' : '上传文件',//上传描述
						                'fileTypeExts' : '*.jpg;*.png',
						                'swf'      : '<?php echo __PUBLIC__?>/Admin/uploadify/uploadify.swf',
						                'uploader' : '<?php echo U('upload')?>',
						                'buttonText':'选择文件',
						                'fileSizeLimit' : '2000KB',
						                'uploadLimit' : 1,//上传文件数
						                'width':65,
						                'height':25,
						                'successTimeout':10,//等待服务器响应时间
						                'removeTimeout' : 0.2,//成功显示时间
						                'onUploadSuccess' : function(file, data, response) {
						                    //转为json
						                    data=$.parseJSON(data);
						                    
						                    //获得图片地址
						                    var imageUrl = data.url;
						                    //给隐藏域里存放返回的图片地址
						                    //$('#listview').val(data.path);
						                    var li="<li><img src='"+imageUrl+"'/><input type='hidden' name='listview' value='"+data.path+"'/></li>";
						                    $("#uploadList1 ul").prepend(li);
						                }
						            });
						        });
						    </script>
						    <div id="uploadList1">
						        <ul>
									<div id="">
										<img src="<?php echo $oldData['listview']?>"/>
										<input type="hidden" name="listview" value="<?php echo $oldData['listview']?>" />
									<a href="javascript:;" class="close_img">X</a>
									</div>
						        </ul>
						    </div>
						</div>
					</td>
					<td id='pic-list'></td>
				</tr>
			</table>
			
			<table class='table table-bordered'>
				<tr>
					<th colspan="3" class="btn btn-primary">商品图册</th>
				</tr>
				<tr class="info">
					<td>上传图片</td>
					<td>
						<!--<input type="file" name='gdpics' id='photo' />-->
						<!--商品图册多图上传-->
						<div lab="uploadFile">
					    <input id="f" type="file" name='gdpics' multiple="true">
						    <span ">类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
						    <script type="text/javascript">
						        $(function() {
						            $('#f').uploadify({
						                'formData'     : {//POST数据
						                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
						                },
						                'fileTypeDesc' : '上传文件',//上传描述
						                'fileTypeExts' : '*.jpg;*.png',
						                'swf'      : '<?php echo __PUBLIC__?>/Admin/uploadify/uploadify.swf',
						                'uploader' : '<?php echo U('upload')?>',
						                'buttonText':'选择文件',
						                'fileSizeLimit' : '2000KB',
						                'uploadLimit' : 10,//上传文件数
						                'width':65,
						                'height':25,
						                'successTimeout':10,//等待服务器响应时间
						                'removeTimeout' : 0.2,//成功显示时间
						                'onUploadSuccess' : function(file, data, response) {
						                    //转为json
						                    data=$.parseJSON(data);
						                    //获得图片地址
						                    var imageUrl = data.url;
						                    //放隐藏域存放要上传图片的地址
						                    str="<input type='text' name='gdpics[]' value='"+data.path+"'>";
						                    var li="<li><img src='"+imageUrl+"'/><input type='text' name='gdpics[]' value='"+data.path+"'/></li>";
						                    $("#uploadList ul").prepend(li);
						                    //$('#uploadList ul').append(data.path);
						                }
						            });
						        });
						    </script>
									    <div id="uploadList">
									        <ul>
												<?php foreach ($detail as $v){?>
														<?php foreach ($v['gdpics'] as $vv){?>
														<div class="pic">
															<img src="<?php echo $vv?>"/>
															<a href="javascript:;" class="close_img">X</a>
															<input type="hidden" name="gdpics[]" value="<?php echo $vv?>" />
														</div>
														
														<?php }?>
												<?php }?>
									        </ul>
									    </div>
									</div>
								</td>
					<td id='photo-list'></td>
				</tr>
				<script type="text/javascript">
					$(function(){
						//点击关闭图片按钮
						$('.close_img').click(function(){
							//删除图片元素
							$(this).parent().remove();
						})
					})
				</script>
			</table>

			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary">商品详细</th>
				</tr>
				<tr class="hide info">
					<td>
						<textarea name="gdetails" id="intro"><?php echo $detail[0]['gdetails']?></textarea>
					</td>
				</tr>
			</table>

			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary">售后服务</th>
				</tr>
				<tr class="hide info">
					<td>
						<textarea name="gservice" id="service"><?php echo $detail[0]['gservice']?></textarea>
					</td>
				</tr>
			</table>
			<input type="hidden" name='type_typid' value='<?php echo $oldData['type_typid']?>'/>
			<input type="hidden" name="gid"  value= '<?php echo $oldData['gid']?>'/>
			<input type="submit" value="确认修改商品" class="btn btn-primary btn-block btn-large" />
		</fieldset>
	</form>

	</div>
	</div>
	</div>
</body>
</html>